package com.ushine.web.config.duird;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @Author: yls
 * @Date: 2022/02/22 18:17
 * @Description: 扩展连接池，通用配置属性，可应用到所有数据源
 * @Version 1.0
 */
@ConfigurationProperties(prefix = DataSourceCommonProperties.DS, ignoreUnknownFields = false)
@Data
public class DataSourceCommonProperties {

    static final String DS = "spring.datasource.common";

    private int initialSize;
    private int minIdle;
    private int maxIdle;
    private int maxActive;
    private int maxWait;
    private int timeBetweenEvictionRunsMillis;
    private int minEvictableIdleTimeMillis;
    private String validationQuery;
    private boolean testWhileIdle;
    private boolean testOnBorrow;
    private boolean testOnReturn;
    private boolean poolPreparedStatements;
    private int maxOpenPreparedStatements;
    private String filters;
    private String mapperLocations;
    private String typeAliasPackage;
    private String useGlobalDataSourceStat;
    private boolean logAbandoned;
    private boolean removeAbandoned;
    private int removeAbandonedTimeout;

    public void getCommonProperties(DruidDataSource datasource) {
        //配置统一属性
        datasource.setInitialSize(getInitialSize());
        datasource.setMinIdle(getMinIdle());
        datasource.setMaxActive(getMaxActive());
        datasource.setMaxWait(getMaxWait());
        datasource.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
        datasource.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
        datasource.setValidationQuery(getValidationQuery());
        datasource.setTestWhileIdle(isTestWhileIdle());
        datasource.setTestOnBorrow(isTestOnBorrow());
        datasource.setTestOnReturn(isTestOnReturn());
        datasource.setPoolPreparedStatements(isPoolPreparedStatements());
    }

}
